/*
 * To change this license header, choose License Headers in Project Properties. To change this
 * template file, choose Tools | Templates and open the template in the editor.
 */
package chalmers.game.subterranean.ui.view.world.level;

import chalmers.game.subterranean.util.BlockType;
import chalmers.game.subterranean.util.Position;
import chalmers.game.subterranean.util.options.WorldValues;
import javafx.scene.layout.GridPane;

/**
 * 
 * @author TH
 */
public class Level {
  public final GridPane grid;
  private SquareView[][] theViews;

  public Level() {
    grid = new GridPane();
    theViews = new SquareView[WorldValues.LEVEL_HEIGHT][WorldValues.LEVEL_WIDTH];
  }

  public void add(BlockType blockType, int x, int y) {

    SquareView newView = new SquareView(blockType);

    grid.add(newView.view, x, y);
    theViews[y][x] = newView;
  }

  public void clear() {
    grid.getChildren().clear();
    theViews = new SquareView[WorldValues.LEVEL_HEIGHT][WorldValues.LEVEL_WIDTH];
  }

  public void changeBlock(Position.Point pos, BlockType type) {

    theViews[pos.y][pos.x].setView(type);
  }


  public void destroy(chalmers.game.subterranean.util.Position.Point pos) {
    theViews[pos.y][pos.x].destroy();
  }

  public void setLadder(chalmers.game.subterranean.util.Position.Point pos) {
    theViews[pos.y][pos.x].setLadder();
  }


  public void damage(chalmers.game.subterranean.util.Position.Point pos) {
    theViews[pos.y][pos.x].damage();
  }

}
